
from sklearn.linear_model import RidgeCV, LassoCV
from sklearn.neighbors import KNeighborsRegressor
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.ensemble import StackingRegressor
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split

X, y = load_diabetes(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

estimators = [
    (\'ridge\', RidgeCV()),
    (\'lasso\', LassoCV(random_state=42)),
    (\'knr\', KNeighborsRegressor(n_neighbors=20, metric=\'euclidean\'))
]

final_estimator = GradientBoostingRegressor(
    n_estimators=25,
    subsample=0.5,
    min_samples_leaf=25,
    max_features=1,
    random_state=42
)

reg = StackingRegressor(
    estimators=estimators,
    final_estimator=final_estimator
)

reg.fit(X_train, y_train)
y_pre = reg.predict(X_test)
print(y_pre)


